﻿<Window x:Class="AscendViewer.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:asc="clr-namespace:Ascend;assembly=Ascend"
        Title="AscendViewer" Height="600" Width="800">

	<Window.Resources>
		<ResourceDictionary>
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="/Styles/AscendStyles.xaml"/>
				<ResourceDictionary Source="/Views/ContentExplorer.xaml"/>
			</ResourceDictionary.MergedDictionaries>

			<!-- Animation button styles -->
			<Style x:Key="PrevNextButtonStyle" TargetType="{x:Type Button}">
				<Setter Property="Margin" Value="5,2"/>
				<Setter Property="Template">
					<Setter.Value>
						<ControlTemplate TargetType="{x:Type Button}">
							<Grid Background="Transparent" MinWidth="18" MinHeight="18">
								<Path x:Name="PART_Graphic" Data="M 4,0L 0,4L 4,8 M 10,0L 6,4L 10,8" Stroke="#BABABA" StrokeThickness="2.5"
									  StrokeStartLineCap="Square" StrokeEndLineCap="Square" Margin="4,3,4,1"
									  HorizontalAlignment="Center" VerticalAlignment="Center"/>
							</Grid>

							<ControlTemplate.Triggers>
								<Trigger Property="IsMouseOver" Value="True">
									<Setter TargetName="PART_Graphic" Property="Stroke" Value="#A5A5A5"/>
								</Trigger>
								<Trigger Property="IsPressed" Value="True">
									<Setter TargetName="PART_Graphic" Property="Stroke" Value="#959595"/>
								</Trigger>
								<Trigger Property="IsEnabled" Value="False">
									<Setter TargetName="PART_Graphic" Property="Stroke" Value="#88BABABA"/>
								</Trigger>
							</ControlTemplate.Triggers>
						</ControlTemplate>
					</Setter.Value>
				</Setter>
			</Style>

			<Style x:Key="PlayPauseButtonStyle" TargetType="{x:Type ToggleButton}">
				<Setter Property="Margin" Value="2"/>
				<Setter Property="Template">
					<Setter.Value>
						<ControlTemplate TargetType="{x:Type ToggleButton}">
							<Grid Background="Transparent" MinWidth="14" MinHeight="18">
								<Path x:Name="PART_Graphic" Data="M 0,0.5L 0,7.5L 4,4 Z" Stroke="#BABABA" Fill="#BABABA"
									  StrokeThickness="2.5" StrokeStartLineCap="Square" StrokeEndLineCap="Square"
									  HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5,3,1,1"/>
							</Grid>

							<ControlTemplate.Triggers>
								<Trigger Property="IsChecked" Value="True">
									<Setter TargetName="PART_Graphic" Property="Data" Value="M 0,0L 0,7.5 M 4,0L 4,7.5"/>
									<Setter TargetName="PART_Graphic" Property="StrokeThickness" Value="3"/>
								</Trigger>
								<Trigger Property="IsMouseOver" Value="True">
									<Setter TargetName="PART_Graphic" Property="Stroke" Value="#A5A5A5"/>
									<Setter TargetName="PART_Graphic" Property="Fill" Value="#A5A5A5"/>
								</Trigger>
								<Trigger Property="IsPressed" Value="True">
									<Setter TargetName="PART_Graphic" Property="Stroke" Value="#959595"/>
									<Setter TargetName="PART_Graphic" Property="Fill" Value="#959595"/>
								</Trigger>
								<Trigger Property="IsEnabled" Value="False">
									<Setter TargetName="PART_Graphic" Property="Stroke" Value="#88BABABA"/>
									<Setter TargetName="PART_Graphic" Property="Fill" Value="#88BABABA"/>
								</Trigger>
							</ControlTemplate.Triggers>
						</ControlTemplate>
					</Setter.Value>
				</Setter>
			</Style>
			
			<Style x:Key="UpDownButtonStyle" TargetType="{x:Type Button}">
				<Setter Property="Template">
					<Setter.Value>
						<ControlTemplate TargetType="{x:Type Button}">
							<Grid Background="Transparent" MinWidth="16" MinHeight="12">
								<Path x:Name="PART_Graphic" Data="M 6,-5L 11,1L 1,1 Z" Stroke="#BABABA" Fill="#BABABA"
									  StrokeThickness="1.0" StrokeStartLineCap="Square" StrokeEndLineCap="Square"
									  HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,8,0,0"/>
							</Grid>
							
							<ControlTemplate.Triggers>
								<Trigger Property="IsMouseOver" Value="True">
									<Setter TargetName="PART_Graphic" Property="Stroke" Value="#A5A5A5"/>
									<Setter TargetName="PART_Graphic" Property="Fill" Value="#A5A5A5"/>
								</Trigger>
								<Trigger Property="IsPressed" Value="True">
									<Setter TargetName="PART_Graphic" Property="Stroke" Value="#959595"/>
									<Setter TargetName="PART_Graphic" Property="Fill" Value="#959595"/>
								</Trigger>
								<Trigger Property="IsEnabled" Value="False">
									<Setter TargetName="PART_Graphic" Property="Stroke" Value="#88BABABA"/>
									<Setter TargetName="PART_Graphic" Property="Fill" Value="#88BABABA"/>
								</Trigger>
							</ControlTemplate.Triggers>
						</ControlTemplate>
					</Setter.Value>
				</Setter>
			</Style>
		</ResourceDictionary>
	</Window.Resources>

	<Window.Template>
		<ControlTemplate>
			<!-- Wrap in AdornerDecorator so error templates show -->
			<AdornerDecorator>
				<!-- Top-level grid -->
				<Grid>
					<!-- 3D views -->
					<asc:SceneViewer3D Scene="{Binding MainScene}" Background="White"
									   MouseCameraControl="True" KeyboardMouseEmulation="True"
									   MiddleMouseEmulatorKey="LeftAlt" RightMouseEmulatorKey="LeftCtrl"/>

					<asc:SceneViewer3D Scene="{Binding BoneScene}" Background="{x:Null}"
									   MouseCameraControl="True" KeyboardMouseEmulation="True"
									   MiddleMouseEmulatorKey="LeftAlt" RightMouseEmulatorKey="LeftCtrl"/>

					<asc:SceneViewer3D Scene="{Binding AxisScene}" Background="{x:Null}"
									   MouseCameraControl="True" KeyboardMouseEmulation="True"
									   MiddleMouseEmulatorKey="LeftAlt" RightMouseEmulatorKey="LeftCtrl"/>
					<Grid>
						<Grid.RowDefinitions>
							<RowDefinition Height="*"/>
							<RowDefinition Height="Auto"/>
						</Grid.RowDefinitions>
					
						<!-- DockPanel for buttons and content explorer -->
						<DockPanel Grid.Row="0">
							<Grid DockPanel.Dock="Top">
								<Grid.ColumnDefinitions>
									<ColumnDefinition/>
									<ColumnDefinition/>
								</Grid.ColumnDefinitions>
								<Border Grid.Column="0" Grid.ColumnSpan="2" Background="#F0F0F0" Margin="-50,0">
									<Border.Effect>
										<DropShadowEffect BlurRadius="10" Opacity="0.5" Color="#000000" ShadowDepth="0"/>
									</Border.Effect>
								</Border>
								<StackPanel Grid.Column="0" Orientation="Horizontal">
									<Button Content="Open" Command="{Binding OpenFileCommand}"
											Margin="5" HorizontalAlignment="Left"/>
									<Border Background="#D8D8D8" Width="3" Margin="0,2"/>
									<Button Content="Reset Camera" Command="{Binding ResetCameraCommand}"
											Margin="5" HorizontalAlignment="Left"/>
									<CheckBox Content="Lights" IsChecked="{Binding ShowLights}"
											  Margin="5" HorizontalAlignment="Left" VerticalAlignment="Center"/>
									<CheckBox Content="Axes" IsChecked="{Binding ShowAxes}" IsEnabled="{Binding CanShowAxes}"
											  Margin="5" HorizontalAlignment="Left" VerticalAlignment="Center"/>									
								</StackPanel>

								<Button Grid.Column="2" Content="?" VerticalAlignment="Center" HorizontalAlignment="Right"
										Padding="6,1" Margin="5" Command="{Binding OpenHelpCommand}" Width="22"/>
							</Grid>

							<!-- Content explorer -->
							<ContentPresenter DockPanel.Dock="Left" Content="{Binding ContentExplorer}"/>
						</DockPanel>

						<!-- Animation controls -->
						<Grid x:Name="PART_AnimationControls" Grid.Row="1" Margin="0,10,0,0" TextBlock.Foreground="DimGray" Visibility="Collapsed">
							<Grid.RowDefinitions>
								<RowDefinition/>
								<RowDefinition/>
							</Grid.RowDefinitions>
						
							<Border Grid.Row="0" Grid.RowSpan="2" Background="#F0F0F0" Margin="-50,0">
								<Border.Effect>
									<DropShadowEffect BlurRadius="10" Opacity="0.5" Color="#000000" ShadowDepth="0"/>
								</Border.Effect>
							</Border>
						
							<!-- Animation name -->
							<TextBlock Grid.Row="0" Text="{Binding ContentExplorer.AnimationContext.CurrentAnimation}" HorizontalAlignment="Center"
									   FontWeight="SemiBold" FontSize="13" Margin="5,2,5,0"/>
						
							<!-- Controls -->
							<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center" Margin="5,-5,5,3">
								<Button Style="{StaticResource PrevNextButtonStyle}"
										Command="{Binding ContentExplorer.AnimationContext.PreviousAnimationCommand}">
									<Button.LayoutTransform>
										<ScaleTransform ScaleX="1.25" ScaleY="1.25"/>
									</Button.LayoutTransform>
								</Button>
								<ToggleButton x:Name="PART_PlayPauseButton" Style="{StaticResource PlayPauseButtonStyle}"
											  IsChecked="{Binding ContentExplorer.AnimationContext.IsPlaying}">
									<ToggleButton.LayoutTransform>
										<ScaleTransform ScaleX="1.25" ScaleY="1.25"/>
									</ToggleButton.LayoutTransform>
								</ToggleButton>
								<Button Style="{StaticResource PrevNextButtonStyle}"
										Command="{Binding ContentExplorer.AnimationContext.NextAnimationCommand}">
									<Button.LayoutTransform>
										<ScaleTransform ScaleX="-1.25" ScaleY="1.25"/>
									</Button.LayoutTransform>
								</Button>
							</StackPanel>

							<!-- Frame rate -->
							<Grid Grid.Row="0" Grid.RowSpan="2" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="10,0">
								<Grid>
									<Grid.RowDefinitions>
										<RowDefinition Height="Auto"/>
										<RowDefinition Height="Auto"/>
										<RowDefinition Height="Auto"/>
									</Grid.RowDefinitions>
								
									<Grid.ColumnDefinitions>
										<ColumnDefinition/>
										<ColumnDefinition/>
										<ColumnDefinition/>
									</Grid.ColumnDefinitions>
								
									<!-- Up button -->
									<Button x:Name="PART_FrameRateUpButton" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Center" Style="{StaticResource UpDownButtonStyle}"
											Margin="0,0,0,1" Command="{Binding ContentExplorer.AnimationContext.FrameRateUpCommand}"/>
								
									<!-- Text box -->
									<TextBlock Grid.Row="1" Grid.Column="0" Text="Frame rate" ToolTip="Animation speed in frames per second"
											   VerticalAlignment="Center" Margin="0,0,5,0"/>
									<TextBox x:Name="PART_FrameRateTextBox" Grid.Row="1" Grid.Column="1" Width="50" TextAlignment="Center"
											 IsEnabled="{Binding ContentExplorer.AnimationContext.IsPaused}" VerticalAlignment="Center">
										<TextBox.Text>
											<Binding Path="ContentExplorer.AnimationContext.FrameRate" UpdateSourceTrigger="PropertyChanged">
												<Binding.ValidationRules>
													<ExceptionValidationRule/>
												</Binding.ValidationRules>
											</Binding>
										</TextBox.Text>
									</TextBox>

									<!-- Down button -->
									<Button x:Name="PART_FrameRateDownButton" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Center" Style="{StaticResource UpDownButtonStyle}"
											Margin="0,1,0,0" Command="{Binding ContentExplorer.AnimationContext.FrameRateDownCommand}">
										<Button.LayoutTransform>
											<ScaleTransform ScaleY="-1"/>
										</Button.LayoutTransform>
									</Button>
								</Grid>
							</Grid>
						</Grid>
					</Grid>
				</Grid>
			</AdornerDecorator>

			<ControlTemplate.Triggers>
				<DataTrigger Binding="{Binding ContentExplorer.AnimationContext.HasAnimations}" Value="True">
					<Setter TargetName="PART_AnimationControls" Property="Visibility" Value="Visible"/>
				</DataTrigger>
				<Trigger SourceName="PART_FrameRateTextBox" Property="Validation.HasError" Value="True">
					<Setter TargetName="PART_PlayPauseButton" Property="IsEnabled" Value="False"/>
					<Setter TargetName="PART_FrameRateUpButton" Property="IsEnabled" Value="False"/>
					<Setter TargetName="PART_FrameRateDownButton" Property="IsEnabled" Value="False"/>
				</Trigger>
			</ControlTemplate.Triggers>
		</ControlTemplate>
	</Window.Template>
</Window>
